import java.io.*;

public class Convert {

	public static void txtToBinary(String filename) throws IOException {

		String binary= filename.substring(0, filename.length()-4)+".dat";
		
		BufferedReader reader;
		try {
			reader = new BufferedReader(new FileReader(filename));
		} catch(FileNotFoundException e) {
			System.out.println("Filen not found.");
			return;
		}
		
		DataOutputStream writer = new DataOutputStream(new FileOutputStream(binary));
		
		String line="";
		
		try {
			
			while(!(line==null)) {
				reader.readLine();
				
				if(!(line==null)) {
				writer.writeInt(line.length());
				writer.writeBytes(line);
				}
			}
		}
		catch(EOFException eof) {
			System.out.println("End of File");
		}
		

		reader.close();
		writer.close();
	}

}
